// https : // iai.sh.cn/problem/924
// ac 100
#include <bits/stdc++.h>
using namespace std;
const int M = 3e5 + 3;
using LL = long long;
int s[M];
int temp[M];
int n;

LL merge(int L, int m, int R) {
  LL res = 0;
  int i = L;
  int j = m + 1;
  int k = 0;
  while (i <= m && j <= R) {
    if (s[i] <= s[j]) {
      temp[++k] = s[i];
      res += R - j + 1; // 统计满足条件的子区间
      i++;
    } else {
      temp[++k] = s[j];
      j++;
    }
  }
  while (i <= m)
    temp[++k] = s[i++];
  while (j <= R)
    temp[++k] = s[j++];
  copy(temp + 1, temp + k + 1, s + L);
  return res;
}
// 归并排序,求逆序对
LL sort(int L, int R) {
  if (L >= R)
    return 0;
  int m = (L + R) / 2;
  LL ansL = sort(L, m);
  LL ansR = sort(m + 1, R);
  LL ansC = merge(L, m, R);
  return ansC + ansL + ansR;
}

int main() {
  string str;
  cin >> str;
  n = str.size();
  s[0] = 0; // 初始化s[0]为0
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + (str[i - 1] == '0' ? 1 : -1);
  }
  cout << sort(0, n) << endl;
  return 0;
}